package com.kzd.btgame.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import android.widget.TextView
import com.kzd.btgame.R
import com.module.lemlin.image.loadImage
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper


class ServiceCodePopup(
    context: Context, val onClick: (view: View, type: Int) -> Unit,
) :
    BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }


    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_service_code)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)

        contentView.findViewById<TextView>(R.id.tvServiceQrCodeCancel)
            .setOnClickListener {
                dismiss()
            }

        contentView.findViewById<TextView>(R.id.tvServiceQrCodeDown)
            .setOnClickListener {
                onClick(it, mType)
            }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    private var mType: Int = 0

    fun setContent(resId: Any, type: Int): ServiceCodePopup {
        contentView.findViewById<ImageView>(R.id.ivServiceQrCodeImage)
            .loadImage(resId)
        this.mType = type
        return this
    }

}